package com.bjpowernode.pay.controller;

import com.bjpowernode.pay.service.RechargeKuaiQianService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author 麦翔盛
 * @ClassName: NotifyController
 * @Package: com.bjpowernode.pay.controller
 * @description: 异步通知接口
 * @date 2022/5/31 14:28
 */
@RestController
@CrossOrigin
public class NotifyController {

    @Resource
    private RechargeKuaiQianService rechargeKuaiQianService;

    /**
     * http://localhost:9000/pay/notify/kq?merchantAcctId=1001214035601&signType=4&orderId=KQ202205311842578349&orderAmount=1&payAmount=1&payResult=10&signMsg=FbBOrXH1d3OR
     * @param request 请求
     * @return
     */
    @GetMapping("/notify/kq")
    @ResponseBody
    public String kuaiQianNotify(HttpServletRequest request){
        System.out.println("接受快钱通知");

        //处理异步请求
        rechargeKuaiQianService.handlerNotify(request);

        //无论是否处理成功都返回成功 因为如果一次处理不成功 后面也不可能处理成功
        //后面会有补偿的机制
        return "<result>1</result><redirecturl>http://localhost:8080</redirecturl>";
    }


    /**
     * 接受来自定时任务的请求 对账
     * @return
     */
    @GetMapping("/recharge/kq/query")
    public String kuaiQianQuery(){
        rechargeKuaiQianService.handerKuaiQianQuery();
        return "ok";
    }
}
